﻿using System;
namespace UnityModule
{
    /// <summary>
    /// 引用池信息。
    /// </summary>
    public sealed class ReferencePoolInfo
    {
        /// <summary>
        /// 是否是INeedDispose类型,该类型删除要调ToDestroy
        /// </summary>
        public bool IsNeedDisposeType
        {
            get;
            internal set;
        }
        /// <summary>
        /// 获取引用池类型名称。
        /// </summary>
        public string TypeFullName{ get; internal set; }

        /// <summary>
        /// 获取引用池类型
        /// </summary>
        public Type ReferenceType { get; internal set; }

        /// <summary>
        /// 获取引用池对像空闲数量
        /// </summary>
        public int UnusedReferenceCount { get; internal set; }


        private int m_UsingReferenceCount = 0;
        /// <summary>
        /// 获取引用池对像正在使用数量
        /// </summary>
        public int UsingReferenceCount
        {
            get
            {
                return m_UsingReferenceCount;
            }
            internal set
            {
                m_UsingReferenceCount = value;
                if(m_UsingReferenceCount > MaxReferenceCount)
                {
                    MaxReferenceCount = m_UsingReferenceCount;
                }
            }
        }

        /// <summary>
        /// 记录对像使用过程中,最大使用数量
        /// </summary>
        public int MaxReferenceCount { get; private set; }

        /// <summary>
        /// 获取引用池对像的总数量
        /// </summary>
        public int Count { get { return UsingReferenceCount + UnusedReferenceCount; } }


        /// <summary>
        /// 测试或者调试用于查看池情况
        /// </summary>
        /// <returns></returns>
        public string GetPoolInfoString()
        {
            return string.Format(
                "池类型:{0},池全名:{1},空闲数量:{2},使用中数量{3},池对像最大使用数量{4}." ,
                ReferenceType,TypeFullName, UnusedReferenceCount,UsingReferenceCount,MaxReferenceCount);
        }

    }
}
